﻿/*=================================================================
* 版权信息：Copyright (C) 2005-2011 捷点科技 All Rights Reserved.
* 文件名称：CNVP_ProTypeRefShopMustInfo.cs
* 创建标识：曾乃强 15158756652 2011-04-01 10:04:13
* 修改标识：
* 功能描述：
===================================================================*/
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using CNVP.Framework.Helper;
using CNVP.Config;

namespace CNVP.JShop.DAL
{
    /// <summary>
    /// 对*CNVP_ProTypeRefShopMustInfo*操作数据库(针对SQL Server)的实现
    /// </summary>
    public class CNVP_ProTypeRefShopMustInfo
    {
       private string Prefix = DBConfig.Prefix;
        #region DAL
        public int Insert(Model.CNVP_ProTypeRefShopMustInfo obj)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("insert into  " + Prefix + "ProTypeRefShopMustInfo ([ProductTypeID],[MustInfoName],[ShowWay],[MustInfoValue])");
            sql.Append("values(@ProductTypeID,@MustInfoName,@ShowWay,@MustInfoValue)");
            sql.Append(";SELECT @@IDENTITY");
            SqlParameter[] pra = {
                            new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@MustInfoName",obj.MustInfoName),
							new SqlParameter("@ShowWay",obj.ShowWay),
							new SqlParameter("@MustInfoValue",obj.MustInfoValue)
                                 };
            return Convert.ToInt32(DbHelper.ExecuteScalar(sql.ToString(), pra));
        }

        public int Update(Model.CNVP_ProTypeRefShopMustInfo obj)
        {
             StringBuilder sql = new StringBuilder();
             sql.Append("update " + Prefix + "ProTypeRefShopMustInfo set [ProductTypeID] = @ProductTypeID,[MustInfoName] = @MustInfoName,[ShowWay] = @ShowWay,[MustInfoValue] = @MustInfoValue where [ID] = @ID");

            SqlParameter[] pra = { 
                            new SqlParameter("@ID",obj.ID),
							new SqlParameter("@ProductTypeID",obj.ProductTypeID),
							new SqlParameter("@MustInfoName",obj.MustInfoName),
							new SqlParameter("@ShowWay",obj.ShowWay),
							new SqlParameter("@MustInfoValue",obj.MustInfoValue)
                                };
             return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }

        public int Delete(Model.CNVP_ProTypeRefShopMustInfo obj)
        {
           StringBuilder sql = new StringBuilder();
           sql.Append("delete from " + Prefix + "ProTypeRefShopMustInfo where [ID] = @ID");
           SqlParameter[] pra = {
                                new SqlParameter("@ID",obj.ID)
						
                                };
           return DbHelper.ExecuteNonQuery(sql.ToString(),pra);
        }


        public Model.CNVP_ProTypeRefShopMustInfo LoadById(int ID)
        {
            
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ProductTypeID],[MustInfoName],[ShowWay],[MustInfoValue] from " + Prefix + "ProTypeRefShopMustInfo");
            sql.Append(" where [ID] = @ID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ID",ID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            Model.CNVP_ProTypeRefShopMustInfo cnvp_protyperefshopmustinfo = new Model.CNVP_ProTypeRefShopMustInfo();
            if (DT != null && DT.Rows.Count > 0)
            {
                DataRow dr = DT.Rows[0];
                cnvp_protyperefshopmustinfo.ProductTypeID = dr["ProductTypeID"] is DBNull ? 0 : (int)dr["ProductTypeID"];
                cnvp_protyperefshopmustinfo.MustInfoName = dr["MustInfoName"] is DBNull ? String.Empty : (string)dr["MustInfoName"];
                cnvp_protyperefshopmustinfo.ShowWay = dr["ShowWay"] is DBNull ? (byte)0 : (byte)dr["ShowWay"];
                cnvp_protyperefshopmustinfo.MustInfoValue = dr["MustInfoValue"] is DBNull ? String.Empty : (string)dr["MustInfoValue"];
            }   
             return cnvp_protyperefshopmustinfo;
        }

        #endregion

        /// <summary>
        /// 查看，产品类型ID
        /// </summary>
        /// <param name="ProductTypeID">产品类型ID</param>
        /// <returns></returns>
        public List<Model.CNVP_ProTypeRefShopMustInfo> LoadAll(int ProductTypeID)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("select [ID],[MustInfoName],[ShowWay],[MustInfoValue] from " + Prefix + "ProTypeRefShopMustInfo");
            sql.Append(" where [ProductTypeID] = @ProductTypeID");
            SqlParameter[] pra = {
                                 new SqlParameter("@ProductTypeID",ProductTypeID)
						
                                    };
            DataTable DT = DbHelper.ExecuteTable(sql.ToString(),pra);
            List<Model.CNVP_ProTypeRefShopMustInfo> list = new List<Model.CNVP_ProTypeRefShopMustInfo>();
            if (DT != null && DT.Rows.Count > 0)
            {
                foreach (DataRow dr in DT.Rows)
                {
                    Model.CNVP_ProTypeRefShopMustInfo cnvp_protyperefshopmustinfo = new Model.CNVP_ProTypeRefShopMustInfo();
                    cnvp_protyperefshopmustinfo.ID = dr["ID"] is DBNull ? 0 : (int)dr["ID"];
                    cnvp_protyperefshopmustinfo.MustInfoName = dr["MustInfoName"] is DBNull ? String.Empty : (string)dr["MustInfoName"];
                    cnvp_protyperefshopmustinfo.ShowWay = dr["ShowWay"] is DBNull ? (byte)0 : (byte)dr["ShowWay"];
                    cnvp_protyperefshopmustinfo.MustInfoValue = dr["MustInfoValue"] is DBNull ? String.Empty : (string)dr["MustInfoValue"];
                    list.Add(cnvp_protyperefshopmustinfo);
                }
            }
            return list;
        }
        public int DeleteNotIn(int ProductTypeID, string nowid)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append("delete from " + Prefix + "ProTypeRefShopMustInfo where [ProductTypeID]=" + ProductTypeID + " and [ID] not in (" + nowid + ")");
            return DbHelper.ExecuteNonQuery(sql.ToString());
        }
    }
}

